package com.prs.crm.domain.sale;

import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.Cascade;

import com.prs.crm.domain.FlowCodeEntity;
import com.prs.crm.domain.crm.Customer;
import com.prs.crm.domain.hr.Person;

@Entity
@Table(name = "sale_salesContract")
public class SalesContract extends FlowCodeEntity {

	private static final long serialVersionUID = 1L;

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Integer id;
	/**
	 * 关联客户
	 */
	@ManyToOne
	private Customer customer;
	/**
	 * 合同编号
	 */
	private String contractCode;

	
	/**
	 * 合同主题
	 */
	private String contractName;

	/**
	 * 签订日期
	 */
	private Date signDate;

	/**
	 * 开始日期
	 */
	private Date startDate;

	/**
	 * 终止日期
	 */
	private Date overDate;

	/**
	 * 我方负责人
	 */
	@ManyToOne
	private Person myDelegrate;

	/**
	 * 对方负责人
	 */

	private String otherDelegrate;

	/**
	 * 合同分类
	 */
	@ManyToOne
	private SalesContractType contractType;

	/**
	 * 合同状态
	 */
	private String contractState;

	/**
	 * 产品明细
	 */
	@OneToMany(mappedBy = "salesContract")
	@Cascade( { org.hibernate.annotations.CascadeType.ALL,
			org.hibernate.annotations.CascadeType.DELETE_ORPHAN })
	private Set<SalesContractDetail> details;
	/**
	 * 合同概要
	 */
	@Lob
	private String contractRemark;
	/**
	 * 附件
	 */
	private String contractAttach;
	/**
	 * 发货状态0没有完成1完成
	 */
	private int ShippingState;
	/**
	 * 
	 * 退货状态 0没有退货 1
	 */
	@Column(columnDefinition = "Integer(2) default '0'")
	private int returnState;
	/**
	 * 合同单收款状态
	 * 
	 * @return
	 */
	@Column(columnDefinition = "Integer(2) default '0'")
	private Integer receiptState;

	// /**
	// * 合同单发货状态
	// *
	// * @return
	// */
	// @Column(columnDefinition = "Integer(2) default '1'")
	// private Integer sendState;
	//	
	// /**
	// * 合同单发货数量
	// *
	// * @return
	// */
	// @Column(columnDefinition = "double(250,3) default '0.000'")
	// private Double sendNum;
	/**
	 * 已经付出的金额
	 */
	@Column(columnDefinition = "double(250,3) default '0.000'")
	private Double payedMoney;
	// /**
	// * 合同收款余额
	// *
	// * @return
	// */
	// @Column(columnDefinition = "double(250,3) default '0.000'")
	// private Double contactMonly;
	/**
	 * 已开付款单的金额
	 * 
	 * @return
	 */
	@Column(columnDefinition = "double(250,3) default '0.000'")
	private Double receiveMoney;
	/**
	 * 已经归还金额
	 * 
	 * @return
	 */
	@Column(columnDefinition = "double(250,3) default '0.000'")
	private Double money;

	public int getReturnState() {
		return returnState;
	}

	public void setReturnState(int returnState) {
		this.returnState = returnState;
	}

	public int getShippingState() {
		return ShippingState;
	}

	public void setShippingState(int shippingState) {
		ShippingState = shippingState;
	}

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public Customer getCustomer() {
		return customer;
	}

	public void setCustomer(Customer customer) {
		this.customer = customer;
	}

	public String getContractCode() {
		return contractCode;
	}

	public void setContractCode(String contractCode) {
		this.contractCode = contractCode;
	}

	public String getContractName() {
		return contractName;
	}

	public void setContractName(String contractName) {
		this.contractName = contractName;
	}

	public Date getSignDate() {
		return signDate;
	}

	public void setSignDate(Date signDate) {
		this.signDate = signDate;
	}

	public Date getStartDate() {
		return startDate;
	}

	public void setStartDate(Date startDate) {
		this.startDate = startDate;
	}

	public Date getOverDate() {
		return overDate;
	}

	//	
	// public Integer getSendState() {
	// return sendState;
	// }
	//	
	// public void setSendState(Integer sendState) {
	// this.sendState = sendState;
	// }

	public void setOverDate(Date overDate) {
		this.overDate = overDate;
	}

	public Person getMyDelegrate() {
		return myDelegrate;
	}

	public void setMyDelegrate(Person myDelegrate) {
		this.myDelegrate = myDelegrate;
	}

	public String getOtherDelegrate() {
		return otherDelegrate;
	}

	public void setOtherDelegrate(String otherDelegrate) {
		this.otherDelegrate = otherDelegrate;
	}

	public SalesContractType getContractType() {
		return contractType;
	}

	public void setContractType(SalesContractType contractType) {
		this.contractType = contractType;
	}

	public String getContractState() {
		return contractState;
	}

	public void setContractState(String contractState) {
		this.contractState = contractState;
	}

	public Set<SalesContractDetail> getDetails() {
		return details;
	}

	public void setDetails(Set<SalesContractDetail> details) {
		this.details = details;
	}

	public String getContractRemark() {
		return contractRemark;
	}

	public void setContractRemark(String contractRemark) {
		this.contractRemark = contractRemark;
	}

	public void addDetail(SalesContractDetail detail) {
		if (details == null)
			details = new HashSet<SalesContractDetail>();
		detail.setSalesContract(this);
		details.add(detail);
	}

	public String getContractAttach() {
		return contractAttach;
	}

	public void setContractAttach(String contractAttach) {
		this.contractAttach = contractAttach;
	}

	public Integer getReceiptState() {
		return receiptState;
	}

	public void setReceiptState(Integer receiptState) {
		this.receiptState = receiptState;
	}

	// public Double getContactMonly() {
	// return contactMonly;
	// }
	//
	// public void setContactMonly(Double contactMonly) {
	// this.contactMonly = contactMonly;
	// }
	//
	// public Double getSendNum() {
	// return sendNum;
	// }
	//
	// public void setSendNum(Double sendNum) {
	// this.sendNum = sendNum;
	// }

	public Double getPayedMoney() {
		return payedMoney;
	}

	public void setPayedMoney(Double payedMoney) {
		this.payedMoney = payedMoney;
	}

	public Double getReceiveMoney() {
		return receiveMoney;
	}

	public void setReceiveMoney(Double receiveMoney) {
		this.receiveMoney = receiveMoney;
	}

	public Double getMoney() {
		return money;
	}

	public void setMoney(Double money) {
		this.money = money;
	}

}
